package com.fight.strive.sys.modules.dictionary.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fight.strive.sys.modules.common.PageR;
import com.fight.strive.sys.modules.common.ReStatus;
import com.fight.strive.sys.modules.dictionary.entity.DataDictionaryEntity;
import com.fight.strive.sys.modules.dictionary.service.DataDictionaryService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/sys/dataDictionary")
public class DataDictionaryController {

    @Resource
    private DataDictionaryService dictService;

    @PostMapping("/save")
    public ReStatus<Void> save(@RequestBody DataDictionaryEntity entity) {
        dictService.saveDict(entity);
        return ReStatus.success();
    }

    @PostMapping("/list")
    public ReStatus<IPage<DataDictionaryEntity>> list(
            @RequestBody PageR<DataDictionaryEntity> page) {
        return ReStatus.success(
                dictService.listByPage(page));
    }

    @PostMapping("/remove")
    public ReStatus<Void> get(@RequestBody DataDictionaryEntity entity) {
        dictService.removeDict(entity);
        return ReStatus.success();
    }

    @RequestMapping("/get/{id}")
    public ReStatus<DataDictionaryEntity> remove(@PathVariable Long id) {
        return ReStatus.success(
                dictService.getDictById(id));
    }

}
